<% add_decidim_page_title(t(".title")) %>

<% provide :title do %>
  <h1 class="h1"><%= t ".title" %></h1>
<% end %>

<%= decidim_form_for(@form, url: organization_path(@organization)) do |f| %>
  <div class="form__wrapper">
    <div>
      <%= f.translated :text_field, :name, autofocus: true %>
    </div>

    <%= f.text_field :host %>

    <%= f.text_area :secondary_hosts, help_text: t(".secondary_hosts_hint") %>

    <%= field_set_tag f.label(:force_authentication, nil, for: nil) do %>
      <%= f.check_box :force_users_to_authenticate_before_access_organization, label_options: { class: "form__wrapper-checkbox-label" } %>
    <% end %>

    <%= field_set_tag f.label(:users_registration_mode, nil, for: nil) do %>
      <%= f.collection_radio_buttons :users_registration_mode,
                                     Decidim::Organization.users_registration_modes,
                                     :first,
                                     ->(mode) { t("decidim.system.organizations.users_registration_mode.#{mode.first}") } do |builder|
                                      builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.radio_button(id: nil) + builder.text }
                                    end %>
    <% end %>

    <%= field_set_tag f.label(:available_authorizations, nil, for: nil) do %>
      <%= f.collection_check_boxes :available_authorizations, Decidim.authorization_workflows, :name, :description do |builder|
        builder.label(for: nil, class: "form__wrapper-checkbox-label") { builder.check_box(id: nil) + builder.text }
      end %>
    <% end %>

    <% if Decidim.enable_html_header_snippets %>
      <%= f.text_area :header_snippets, help_text: t("decidim.system.organizations.header_snippets_help_html"), rows: 10 %>
    <% end %>

    <%= render partial: "advanced_settings", locals: { f: } %>
  </div>

  <div class="form__wrapper-block flex-col-reverse md:flex-row justify-between">
    <% if @organization&.users&.first&.invitation_pending? %>
      <%= link_to t(".resend_invitation"),
                  resend_invitation_organization_path(@organization),
                  method: :post,
                  class: "button button__sm md:button__lg button__transparent-secondary",
                  data: { confirm: t(".confirm_resend_invitation") } %>
    <% end %>
    <%= f.submit t("decidim.system.actions.save"), class: "button button__sm md:button__lg button__primary" %>
  </div>
<% end %>
